home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * XmlDocument.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
- if (!IS.isModuleInitialized("IS.NOF.XML.XmlDocument"))
- {
-
- /****h* NOF_JavaScript_Library/NOF.XML.XmlDocument
- *
- * NAME
- * NOF.XML.XmlDocument
- *
- * DESCRIPTION
- *
- *
- ****/
-
- /**
- * Constructor
- */
- function XML_XmlDocument( ) {
- this.__proto__ = XML_XmlDocument.prototype;
- }
- {
- var member = XML_XmlDocument.prototype;
-
- member.prefix = null;
- member.prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
-
- var method = XML_XmlDocument.prototype;
-
- /**
- * Private method. Used to find the Automation server name
- * Only for Microsoft's ActiveX.
- *
- * @return
- **/
- method.getDomDocumentPrefix = function () {
- if (this.prefix) {
- return ("" + this.prefix);
- }
-
- var o;
- for (var i = 0; i < this.prefixes.length; i++) {
- try {
- // try to create the objects
- o = new ActiveXObject(this.prefixes[i] + ".DomDocument");
- this.prefix = this.prefixes[i];
- return ("" + this.prefix);
- } catch (ex) {
- }
- }
- //alert("Could not find an installed XML parser");
- throw new Error("Could not find an installed XML parser");
- //throw new NOF.UTIL.Exception();
- }
-
- /**
- * Creates an instance of the DomDocument
- *
- * @return
- **/
- method.create = function (/*? document ?*/) {
- try {
- if (window.ActiveXObject) {
- return new ActiveXObject(this.getDomDocumentPrefix() + ".DomDocument");
- }
-
- // DOM2
- if (document.implementation && document.implementation.createDocument) {
- var doc = document.implementation.createDocument("", "", null);
-
- // some versions of Moz do not support the readyState property
- // and the onreadystate event so we patch it!
- if (doc.readyState == null) {
- doc.readyState = 1;
- doc.addEventListener("load", function () {
- doc.readyState = 4;
- if (typeof(doc.onreadystatechange) == "function") {
- doc.onreadystatechange();
- }
- }, false);
- }
-
- return doc;
- }
- }
- catch (ex) {}
- //alert("Your browser does not support XmlDocument objects");
- throw new Error("Your browser does not support XmlDocument objects");
- //throw new NOF.UTIL.Exception();
- }
-
- /**
- * Create the loadXML method and xml getter for Mozilla
- **/
- if (window.DOMParser && window.XMLSerializer && window.Node && Node.prototype && Node.prototype.__defineGetter__) {
-
- // XMLDocument did not extend the Document interface in some versions
- // of Mozilla. Extend both!
- //XMLDocument.prototype.loadXML =
- Document.prototype.loadXML = function (s) {
-
- // parse the string to a new doc
- var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
-
- // remove all initial children
- while (this.hasChildNodes())
- this.removeChild(this.lastChild);
-
- // insert and import nodes
- for (var i = 0; i < doc2.childNodes.length; i++) {
- this.appendChild(this.importNode(doc2.childNodes[i], true));
- }
- };
-
-
- /*
- * xml getter
- *
- * This serializes the DOM tree to an XML String
- *
- * Usage: var sXml = oNode.xml
- *
- */
- // XMLDocument did not extend the Document interface in some versions
- // of Mozilla. Extend both!
- /*
- XMLDocument.prototype.__defineGetter__("xml", function () {
- return (new XMLSerializer()).serializeToString(this);
- });
- */
- Document.prototype.__defineGetter__("xml", function () {
- return (new XMLSerializer()).serializeToString(this);
- });
- }
-
- /**
- * Determine the prefix of the given namespace in a XML Document
- * @param xmldoc - instance of the DOM document to search in.
- * @param nsURL - namespace as URL
- * @param nsPrefix - default prefix (returned if no other NS is found)
- * @return prefix
- **/
- method.getNSPrefix = function (/*Document*/ xmldoc,/*String*/ nsURL,/*String*/ nsPrefix) {
- var prefix = nsPrefix;
- var node = xmldoc.documentElement;
- //xmlns:lpb="http://www.netobjects.com/fusion/etc"
- for (var i = 0; i < node.attributes.length; i++) {
- if (node.attributes[i].value == nsURL) {
- prefix = node.attributes[i].name;
- var j = prefix.indexOf("xmlns");
- if (j > -1) {
- j = prefix.indexOf(":", j);
- prefix = prefix.substring(j+1, prefix.length);
- }
- break;
- }
- }
- return prefix;
- }
-
- }
-
- NOF.XML.__proto__.XmlDocument = new XML_XmlDocument();
- }
-
-
-
-